package com.eyolas.passwordmanager.model;

import java.io.Serializable;

import com.eyolas.passwordmanager.dao.AccountDao;
import com.eyolas.passwordmanager.utils.SimpleCrypto;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;

@DatabaseTable(tableName="t_account_acc", daoClass=AccountDao.class)
public class Account implements IModel,Serializable {
	private static final long serialVersionUID = -793426206714519786L;
	
	@DatabaseField(generatedId=true,columnName="acc_id")
	private int id;
	
	@DatabaseField(canBeNull=false,columnName="acc_name")
	private String name;
	
	@DatabaseField(canBeNull=false,columnName="acc_login")
	private String login;
	
	@DatabaseField(canBeNull=false,columnName="acc_password")
	private String password;
	
	@DatabaseField(canBeNull=false,columnName="acc_category", foreign=true, foreignAutoRefresh=true)
	private Category category;
	
	public Account(){}
	
	public Account(String name, String login, String password, Category category){
		this.name = name;
		this.login = login;
		this.password = password;
		this.category = category;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getLogin() {
		return login;
	}

	public void setLogin(String login) {
		this.login = login;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Category getCategory() {
		return category;
	}

	public void setCategory(Category category) {
		this.category = category;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getDecryptPassword(String seed) {
		try {
			return SimpleCrypto.decrypt(seed, getPassword());
		} catch (Exception e) {
			return "";
		}
	}
}
